package xhwl.insurance.ui;

import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import xhwl.android.common.log.XHLog;
import xhwl.android.common.util.ToastUtil;
import xhwl.insurance.R;
import xhwl.insurance.adapter.BaseFragmentAdapter;
import xhwl.insurance.ui.fragment.LauncherBaseFragment;
import xhwl.insurance.ui.fragment.OneBootPageFragment;
import xhwl.insurance.ui.fragment.PictureSlideFragmentOne;
import xhwl.insurance.ui.fragment.PictureSlideFragmentOneThree;
import xhwl.insurance.ui.fragment.PictureSlideFragmentOneTwo;
import xhwl.insurance.ui.fragment.TwoBootPageFragment;
import xhwl.insurance.view.GuideViewPager;

/**
 * Created by fuyi on 2017/10/20.
 */

public class PictureSlideActivity extends FragmentActivity {
    private GuideViewPager vPager;
    private List<LauncherBaseFragment> list = new ArrayList<LauncherBaseFragment>();
    private BaseFragmentAdapter adapter;
    private int currentSelect;
    private String imgshow;
    private String imgshow2;
    private String imgshow3, type;
    private TextView mTextView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_pictureslide);

        imgshow = getIntent().getStringExtra("imgshow");
        imgshow2 = getIntent().getStringExtra("imgshow2");
        imgshow3 = getIntent().getStringExtra("imgshow3");
        type = getIntent().getStringExtra("type");
        //获取自定义viewpager 然后设置背景图片
        vPager = (GuideViewPager) findViewById(R.id.viewpager_pictureslide);
        mTextView = (TextView) findViewById(R.id.tv_pictureslide);
//        vPager.setBackGroud(BitmapFactory.decodeResource(getResources(), R.color.welinecolor));
        /**
         * 初始化三个fragment  并且添加到list中
         */
        PictureSlideFragmentOne oneFragment = new PictureSlideFragmentOne();
        PictureSlideFragmentOneTwo twoFragment = new PictureSlideFragmentOneTwo();
        PictureSlideFragmentOneThree threeFragment = new PictureSlideFragmentOneThree();
        list.add(oneFragment);
        list.add(twoFragment);
        list.add(threeFragment);
        adapter = new BaseFragmentAdapter(getSupportFragmentManager(), list);
        vPager.setOffscreenPageLimit(1);
        vPager.setAdapter(adapter);
        if (type.equals("1")) {
            vPager.setCurrentItem(0);
            mTextView.setText("1/3");

        } else if (type.equals("2")) {
            vPager.setCurrentItem(1);
            mTextView.setText("2/3");

        } else if (type.equals("3")) {
            vPager.setCurrentItem(2);
            mTextView.setText("3/3");
        } else {

        }

        vPager.addOnPageChangeListener(changeListener);
    }

    public String getData() {
        return imgshow;
    }

    public String getData2() {
        return imgshow2;
    }

    public String getData3() {
        return imgshow3;
    }

    /**
     * 监听viewpager的移动
     */
    ViewPager.OnPageChangeListener changeListener = new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageSelected(int index) {
            if (index == 0) {
                mTextView.setText("1/3");
            } else if (index == 1) {
                mTextView.setText("2/3");
            } else if (index == 2) {
                mTextView.setText("3/3");
            } else {

            }


            LauncherBaseFragment fragment = list.get(index);
            list.get(currentSelect).stopAnimation();//停止前一个页面的动画
            fragment.startAnimation();//开启当前页面的动画

            currentSelect = index;


        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    };

}
